package com.authine.cloudpivot.web.api.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.authine.cloudpivot.engine.api.facade.TaskReportFacade;
import com.authine.cloudpivot.engine.api.model.bizmodel.BizSchemaModel;
import com.authine.cloudpivot.engine.api.model.organization.UserModel;
import com.authine.cloudpivot.engine.api.model.runtime.BizObjectModel;
import com.authine.cloudpivot.engine.api.model.runtime.BizObjectQueryModel;
import com.authine.cloudpivot.engine.api.model.runtime.SelectionValue;
import com.authine.cloudpivot.engine.component.query.api.FilterExpression;
import com.authine.cloudpivot.engine.component.query.api.Page;
import com.authine.cloudpivot.engine.component.query.api.helper.PageableImpl;
import com.authine.cloudpivot.engine.component.query.api.helper.Q;
import com.authine.cloudpivot.engine.enums.type.QueryDisplayType;
import com.authine.cloudpivot.web.api.dao.ProjectTeamMapper;
import com.authine.cloudpivot.web.api.dao.UserMapper;
import com.authine.cloudpivot.web.api.dubbo.DubboConfigService;
import com.authine.cloudpivot.web.api.quartz.task.JobManger;
import com.authine.cloudpivot.web.api.service.AsyncDataService;
import com.authine.cloudpivot.web.api.service.ExecuteService;
import com.authine.cloudpivot.web.api.service.FescoadQueryService;
import com.authine.cloudpivot.web.api.service.RecruitmentService;
import com.authine.cloudpivot.web.api.vo.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.ibatis.annotations.Param;
import org.joda.time.DateTimeConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ExecuteServiceImpl implements ExecuteService {

    @Reference(version = "1.00")
    private TaskReportFacade taskReportFacade;

    @Autowired
    private DubboConfigService dubboConfigService;

    @Autowired
    private RecruitmentService recruitmentService;

    @Autowired
    private ProjectTeamMapper projectTeamMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private JobManger jobManger;

    @Autowired
    private FescoadQueryServiceImpl fescoadQueryService;

    @Autowired
    private AsyncDataService asyncDataService;

    @Override
    public void createExecuteReport(String id) {
        //根据id获取招聘需求提报的相关信息
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryModel.setSchemaCode("ZXXQTB");
        queryModel.setQueryCode("ZXXQTB");
        queryModel.setPageable(pageable);
        FilterExpression filterExpression = Q.it("id", FilterExpression.Op.Eq, id);
        queryModel.setFilterExpr(filterExpression);
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("id","creater","createdDeptId","demandCreatedTime", "activityStartTime","activityEndTime",
                "operator","postJD","executeDetails","projectName","recruitmentType","frontOperator","operator","activityName", "projectNameStr",
                "industry","qthysm","projectNameStr","jobNature","subjectPerson"));
        queryModel.setOptions(option);
        Page<BizObjectModel> executeDatas = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);

        //生成周报
        BizObjectModel model = executeDatas.getContent().get(0);
        Map<String, Object> executeData = model.getData();
        String demandId = (String) executeData.get("id");
        SelectionValue user = ((ArrayList<SelectionValue>) executeData.get("creater")).get(0);
        String userId = user.getId();
        String projectName  = (String) ((HashMap<String,Object>)executeData.get("projectName")).get("id");
        List<Map<String, Object>> persons = recruitmentService.getMembers(projectName);
        executeData.put("persons",persons);
        BizSchemaModel bizSchemaModel = dubboConfigService.getAppManagementFacade().getBizSchemaBySchemaCode("ZXXQTB");
        dubboConfigService.getBizObjectFacade().updateBizObjectModel(userId, model, bizSchemaModel);

        //获取周报时间
        Map<String, Object> map = new HashMap<>();
        Date activityEndTime = (Date) executeData.get("activityEndTime");
        Date activityStartTime = (Date) executeData.get("activityStartTime");
        map.put("demandCreatedTime", activityStartTime);
        map.put("demandEndTime",activityEndTime);
        List<String> weeklyReportDays = RecruitmentServiceImpl.getWeeklyDayTime(map);
        List<String> cycles = RecruitmentServiceImpl.getCycle(weeklyReportDays);
        List<String> weeklyReportDayList = new ArrayList<>();
        List<String> cycleList = new ArrayList<>();
        LocalDate today = LocalDate.now();
        String thisMonday = today.with(TemporalAdjusters.previousOrSame( DayOfWeek.MONDAY)).toString();
        String thisSunday = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY )).toString();
        for(int i=0; i<weeklyReportDays.size(); i++){
            if(weeklyReportDays.get(i).compareTo(thisMonday) < 0){
                weeklyReportDayList.add(weeklyReportDays.get(i));
                cycleList.add(cycles.get(i));
            }
        }

        List<String> tempWeeklyReportDayList = new ArrayList<>();
        List<String> tempCycleList = new ArrayList<>();
        for(int i=0; i<weeklyReportDays.size(); i++){
            if(weeklyReportDays.get(i).compareTo(thisSunday) <=0){
                tempWeeklyReportDayList.add(weeklyReportDays.get(i));
                tempCycleList.add(cycles.get(i));
            }
        }
        updateDetailState(demandId, tempCycleList, tempWeeklyReportDayList, thisMonday, thisSunday);

        Map<String,String> reportCreateTimeMap = getReportCreateTime(weeklyReportDayList, cycleList);
        createReport(id, executeData,"ZXXQTB", reportCreateTimeMap);

        //生成周报管理数据
        createReportMgrInfo(id, userId, executeData);
    }

    private void createExcuteDetails(String executeDemandId, Map<String, Object> executeData) {
        List<Map<String, Object>> executeDetails  = (ArrayList<Map<String, Object>>) executeData.get("executeDetailList");
        if(executeDetails != null && executeDetails.size() > 0) {
            SelectionValue user = ((ArrayList<SelectionValue>) executeData.get("creater")).get(0);
            //frontOperator
            Map<String,Object> userMap = new HashMap<>();
            userMap.put("id",user.getId());
            userMap.put("type",3);
            userMap.put("name",user.getName());

            executeDetails = executeDetails.stream().filter(item->item.get("executeId")==null || StringUtils.isBlank(item.get("executeId").toString())).collect(Collectors.toList());
            executeDetails.stream().parallel().forEach(
                 item->{
                     Map<String, Object> data = new HashMap<>();
                     String uuid = UUID.randomUUID().toString().replace("-", "");
                     data.put("executeDemandId", executeDemandId);
                     data.put("executeId", uuid);
                     data.put("year", item.get("year"));
                     data.put("month", item.get("month"));

                     data.put("cycle", item.get("cycle"));
                     data.put("province", item.get("province"));
                     data.put("dateRange", item.get("dateRange"));
                     data.put("city", item.get("city"));
                     data.put("area", item.get("area"));
                     data.put("planRoundNum", item.get("planRoundNum"));
                     data.put("planGearsNum", item.get("planGearsNum"));
                     data.put("storeNum", item.get("storeNum"));
                     data.put("modifier", user.getId());
                     data.put("modifiedTime", new Date());
                     data.put("state","待执行");
                     item.put("executeId",uuid);
                     item.put("needCreateReport",true);
                     taskReportFacade.createExecuteDetail(data);

                 }
            );
        }
    }

    @Override
    public void updateRCSArea(String id, String schemaCode) {
        taskReportFacade.updateRCSArea(id, schemaCode);
    }

    @Override
    public void updateExecuteDemand(String id) {
        //执行需求变更信息
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryModel.setSchemaCode("ZXXQBG");
        queryModel.setQueryCode("ZXXQBG");
        queryModel.setPageable(pageable);
        queryModel.setFilterExpr( Q.it("id", FilterExpression.Op.Eq, id));
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("creater","createdDeptId","demandCreatedTime", "copyDemand","activityStartTime","activityEndTime",
                "postJD","executeDetailList","projectName","recruitmentType","frontOperator","operator","activityName", "projectNameStr","welfareStandard",
                "taxStandard","fxCycle","wagesTime","zxCycle","signatory","contractType","qtxzsm","contractFS","qtfssm","contractDeline","desc",
                "industry","qthysm","attr","demandReceiver","subjectPerson"));
        queryModel.setOptions(option);
        Map<String, Object> updatedDemandData = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel).getContent().get(0).getData();
        String executeDemandId = (String)((HashMap<String, Object>)updatedDemandData.get("copyDemand")).get("id");
        Date activityStartTime =  (Date) updatedDemandData.get("activityStartTime");
        Date newDemandTime =  (Date) updatedDemandData.get("activityEndTime");
        String demandId = (String)((HashMap<String, Object>)updatedDemandData.get("copyDemand")).get("id");
        //将执行需求变更的子表数据同步到执行需求提报子表中
        createExcuteDetails(demandId, updatedDemandData);
        //更新大区
        //updateRCSArea(demandId,);
        //执行需求提报信息
        BizObjectQueryModel queryExecuteModel = new BizObjectQueryModel();
        queryExecuteModel.setSchemaCode("ZXXQTB");
        queryExecuteModel.setQueryCode("ZXXQTB");
        queryExecuteModel.setPageable(pageable);
        queryExecuteModel.setFilterExpr(Q.it("id", FilterExpression.Op.Eq, executeDemandId));
        BizObjectQueryModel.Options executeOption = new BizObjectQueryModel.Options();
        executeOption.setQueryDisplayType(QueryDisplayType.APPEND);
        executeOption.setCustomDisplayColumns(Arrays.asList("creater","createdDeptId","demandCreatedTime", "copyDemand","activityStartTime","activityEndTime",
                "operator","postJD","executeDetails","projectName","recruitmentType","frontOperator","activityName", "projectNameStr","welfareStandard",
                "taxStandard","fxCycle","wagesTime","zxCycle","signatory","contractType","qtxzsm","contractFS","qtfssm","contractDeline","desc","id",
                "industry","qthysm","attr","demandReceiver"));
        queryExecuteModel.setOptions(executeOption);
        BizObjectModel bizObjectModel  = dubboConfigService.getBizObjectFacade().queryBizObjects(queryExecuteModel).getContent().get(0);
        Date oldDemandTime =  (Date) bizObjectModel.getData().get("activityEndTime");
        //String demandId =  (String) bizObjectModel.getData().get("id");
        SelectionValue user = ((ArrayList<SelectionValue>)  bizObjectModel.getData().get("creater")).get(0);
        String userId = user.getId();
        Map<String, Object> demandData = bizObjectModel.getData();
        SelectionValue demandReceiver = ((ArrayList<SelectionValue>) updatedDemandData.get("demandReceiver")).get(0);
        Map<String,Object> demandReceiverMap = new HashMap<>();
        demandReceiverMap.put("id",demandReceiver.getId());
        demandReceiverMap.put("type",3);
        demandReceiverMap.put("name",demandReceiver.getName());
        demandData.put("demandReceiver", Arrays.asList(demandReceiverMap));
        demandData.put("demandEndTime",updatedDemandData.get("demandEndTime"));
        demandData.put("activityStartTime",updatedDemandData.get("activityStartTime"));
        demandData.put("activityEndTime",updatedDemandData.get("activityEndTime"));
        demandData.put("welfareStandard",updatedDemandData.get("welfareStandard"));
        demandData.put("taxStandard",updatedDemandData.get("taxStandard"));
        demandData.put("fxCycle",updatedDemandData.get("fxCycle"));
        demandData.put("wagesTime",updatedDemandData.get("wagesTime"));
        demandData.put("zpCycle",updatedDemandData.get("zpCycle"));
        demandData.put("signatory",updatedDemandData.get("signatory"));
        demandData.put("contractType",updatedDemandData.get("contractType"));
        demandData.put("qtxzsm",updatedDemandData.get("qtxzsm"));
        demandData.put("contractFS",updatedDemandData.get("contractFS"));
        demandData.put("qtfssm",updatedDemandData.get("qtfssm"));
        demandData.put("contractDeline",updatedDemandData.get("contractDeline"));
        demandData.put("desc",updatedDemandData.get("desc"));
        demandData.put("attr",updatedDemandData.get("attr"));

        BizSchemaModel bizSchemaModel = dubboConfigService.getAppManagementFacade().getBizSchemaBySchemaCode("ZXXQTB");
        dubboConfigService.getBizObjectFacade().updateBizObjectModel(userId, bizObjectModel, bizSchemaModel);

        //更新执行周报和执行需求中的执行明细中的门店数和计划场次数和
        List<Map<String, Object>> demandDetails = (ArrayList<Map<String, Object>>)updatedDemandData.get("executeDetailList");
            demandDetails.forEach(item -> {
            if (item.get("executeId") != null) {
                String executeDetailId = item.get("executeId").toString();
                BigDecimal newStoreNum = null;
                if(item.get("newStoreNum") == null){
                    newStoreNum = (BigDecimal)item.get("storeNum");
                }else{
                    newStoreNum = (BigDecimal)item.get("newStoreNum");
                }

                BigDecimal newPlanGearsNum = null;
                if(item.get("newPlanGearsNum") == null){
                    newPlanGearsNum = (BigDecimal)item.get("planGearsNum");
                }else{
                    newPlanGearsNum = (BigDecimal) item.get("newPlanGearsNum");
                }

                BigDecimal newPlanRoundNum = null;
                if(item.get("newPlanRoundNum") == null){
                    newPlanRoundNum = (BigDecimal) item.get("planRoundNum");
                }else{
                    newPlanRoundNum = (BigDecimal) item.get("newPlanRoundNum");
                }
                taskReportFacade.updateExecuteDetail(executeDetailId, newStoreNum, newPlanGearsNum, newPlanRoundNum);
                taskReportFacade.updateExecuteReportInfo(executeDetailId, newStoreNum, newPlanGearsNum, newPlanRoundNum);
            }
        });

        //TODO 处理周报
        updateExecuteReportInfo(demandId, updatedDemandData,oldDemandTime, newDemandTime,"ZXXQBG");
    }

    @Override
    public void closeExecuteDemand(String id) {
        //执行需求关闭信息
        BizObjectQueryModel queryExecuteModel = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryExecuteModel.setSchemaCode("ZXXQGB");
        queryExecuteModel.setQueryCode("ZXXQGB");
        queryExecuteModel.setPageable(pageable);
        queryExecuteModel.setFilterExpr( Q.it("id", FilterExpression.Op.Eq, id));
        BizObjectQueryModel.Options executeOption = new BizObjectQueryModel.Options();
        executeOption.setQueryDisplayType(QueryDisplayType.APPEND);
        executeOption.setCustomDisplayColumns(Arrays.asList("id","copyDemand","executeEndTime"));
        queryExecuteModel.setOptions(executeOption);
        BizObjectModel bizObjectModel  = dubboConfigService.getBizObjectFacade().queryBizObjects(queryExecuteModel).getContent().get(0);
        String executeDemandId = (String)((HashMap<String, Object>)bizObjectModel.get("copyDemand")).get("id");
        Date executeEndTime = (Date)bizObjectModel.get("executeEndTime");


        //执行需求提报信息
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        queryModel.setSchemaCode("ZXXQTB");
        queryModel.setQueryCode("ZXXQTB");
        queryModel.setPageable(pageable);
        queryModel.setFilterExpr(Q.it("id", FilterExpression.Op.Eq, executeDemandId));
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("creater","createdDeptId","demandCreatedTime", "copyDemand","activityStartTime","activityEndTime",
                "operator","postJD","executeDetails","projectName","recruitmentType","frontOperator","activityName", "projectNameStr","welfareStandard",
                "taxStandard","fxCycle","wagesTime","zxCycle","signatory","contractType","qtxzsm","contractFS","qtfssm","contractDeline","desc","id"));
        queryModel.setOptions(option);
        BizObjectModel objectModel  = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel).getContent().get(0);
        Date activityStartTime = (Date) objectModel.get("activityStartTime");
        Date activityEndTime = (Date) objectModel.get("activityEndTime");
        String demandId  = (String) objectModel.get("id");

        Map<String,Object> gbMap = new HashMap<>();
        gbMap.put("demandCreatedTime",activityStartTime);
        gbMap.put("demandEndTime",executeEndTime);
        List<String> gbWeeklyReportDays = RecruitmentServiceImpl.getWeeklyDayTime(gbMap);
        List<String> gbCycles = RecruitmentServiceImpl.getCycle(gbWeeklyReportDays);
        Map<String,Object> tbMap = new HashMap<>();

        tbMap.put("demandCreatedTime",activityStartTime);
        tbMap.put("demandEndTime",activityEndTime);
        List<String> tbWeeklyReportDays = RecruitmentServiceImpl.getWeeklyDayTime(tbMap);
        List<String> tbCycles = RecruitmentServiceImpl.getCycle(tbWeeklyReportDays);
        for(int i =0; i<tbWeeklyReportDays.size(); i++){

            if(!gbWeeklyReportDays.contains(tbWeeklyReportDays.get(i))){
                String[] dateStr = tbWeeklyReportDays.get(i).split("-");
                String year = dateStr[0];
                String month = dateStr[1];
                String cycle = tbCycles.get(i);
                taskReportFacade.updateDetailState(demandId,year,month,cycle,"已关闭");
            }
        }

        if(tbWeeklyReportDays.size() == gbWeeklyReportDays.size()){
            //说明提报结束时间和关闭的结束时间在同一周，只需要需改reportCreateTime
            if(!tbWeeklyReportDays.get(tbWeeklyReportDays.size() -1).equals(gbWeeklyReportDays.get(gbWeeklyReportDays.size()-1))){
                Date reportCreateTime = null;
                String[] dateStr = gbWeeklyReportDays.get(gbWeeklyReportDays.size() - 1).split("-");
                String year = dateStr[0];
                String month = dateStr[1];
                String cycle = gbCycles.get(gbWeeklyReportDays.size() - 1);
                try {
                    reportCreateTime = DateUtils.parseDate(gbWeeklyReportDays.get(gbWeeklyReportDays.size() - 1) + " 23:59:59", "yyyy-MM-dd HH:mm:ss");
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                taskReportFacade.updateExecuteCreateReportTime(demandId,year,month,cycle,reportCreateTime);
            }
        }


        taskReportFacade.updateExecuteMgrInfo(demandId,activityStartTime, executeEndTime);

        taskReportFacade.updateExecuteReportEndTime(demandId, executeEndTime);

        taskReportFacade.updateExecuteDemandEndTime(demandId, executeEndTime);
    }


    private void updateExecuteReportInfo(String demandId, Map<String, Object> demandData,Date oldDemandTime, Date newDemandTime, String schemaCode) {
        String projectName  = (String) ((HashMap<String,Object>)demandData.get("projectName")).get("id");
        List<Map<String, Object>> persons = recruitmentService.getMembers(projectName);
        demandData.put("persons",persons);
        //新增周报
        Date activityStartTime = (Date)demandData.get("activityStartTime");
        demandData.put("demandCreatedTime", activityStartTime);
        demandData.put("demandEndTime",newDemandTime);
        List<String> weeklyReportDays = RecruitmentServiceImpl.getWeeklyDayTime(demandData);
        List<String> cycles = RecruitmentServiceImpl.getCycle(weeklyReportDays);
        List<String> weeklyReportDayList = new ArrayList<>();
        List<String> cycleList = new ArrayList<>();
        LocalDate today = LocalDate.now();
        String thisMonday = today.with(TemporalAdjusters.previousOrSame( DayOfWeek.MONDAY)).toString();
        String thisSunday = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY )).toString();
        for(int i=0; i<weeklyReportDays.size(); i++){
            if(weeklyReportDays.get(i).compareTo(thisMonday) < 0){
                weeklyReportDayList.add(weeklyReportDays.get(i));
                cycleList.add(cycles.get(i));
            }
        }

        List<String> tempWeeklyReportDayList = new ArrayList<>();
        List<String> tempCycleList = new ArrayList<>();
        for(int i=0; i<weeklyReportDays.size(); i++){
            if(weeklyReportDays.get(i).compareTo(thisSunday) <=0){
                tempWeeklyReportDayList.add(weeklyReportDays.get(i));
                tempCycleList.add(cycles.get(i));
            }
        }
        updateDetailState(demandId, tempCycleList, tempWeeklyReportDayList, thisMonday, thisSunday);

        //updateDetailState(demandId, cycleList, weeklyReportDayList, thisMonday,thisSunday);

        taskReportFacade.updateReportCreateTime(demandId, cycleList, weeklyReportDayList);

        Map<String,String> reportCreateTimeMap = getReportCreateTime(weeklyReportDayList, cycleList);

        createReport(demandId, demandData,schemaCode, reportCreateTimeMap);

        //更新执行周报管理
        taskReportFacade.updateExecuteMgrInfo(demandId,activityStartTime, newDemandTime);

        taskReportFacade.updateExecuteDemandEndTime(demandId,newDemandTime);

    }

    private void updateDetailState(String demandId, List<String> cycles, List<String> weeklyReportDayList, String thisMonday, String thisSunday ) {
        for(int i = 0; i< weeklyReportDayList.size(); i++){
            String[] dateStr = weeklyReportDayList.get(i).split("-");
            String year = dateStr[0];
            String month = dateStr[1];
            String cycle = cycles.get(i);
            if(weeklyReportDayList.get(i).compareTo(thisMonday)>= 0 && weeklyReportDayList.get(i).compareTo(thisSunday) <=0){
                taskReportFacade.updateDetailState(demandId,year,month,cycle,"执行中");
            }else{
                taskReportFacade.updateDetailState(demandId,year,month,cycle,"已结束");
            }

        }
    }

    private void createReportMgrInfo(String id, String userId, Map<String, Object> executeData) {
        List<Map<String,Object>> executeDetails = (ArrayList<Map<String,Object>>) executeData.get("executeDetails");

        BizObjectModel bizObjectModel = new BizObjectModel();
        Map<String, Object> data = bizObjectModel.getData();
        bizObjectModel.setSchemaCode("ZXZBGL");
        bizObjectModel.setFormCode("ZXZBGL");
        bizObjectModel.setSequenceStatus("COMPLETED");
        String postJD  =  (String) executeData.get("postJD");
        String jobNature = (String) executeData.get("jobNature");
        String industry = "其他".equals(executeData.get("industry").toString()) ? executeData.get("qthysm").toString() : executeData.get("industry").toString();
        SelectionValue user = ((ArrayList<SelectionValue>) executeData.get("creater")).get(0);
        SelectionValue depart = ((ArrayList<SelectionValue>) executeData.get("createdDeptId")).get(0); // String deptName = ((ArrayList<SelectionValue>) demandData.get("createdDeptId")).get(0).getName();
        //depart
        Map<String, Object> departMap = new HashMap<>();
        departMap.put("id", depart.getId());
        departMap.put("type", 1);
        departMap.put("name", depart.getName());

        //frontOperator
        Map<String, Object> userMap = new HashMap<>();
        userMap.put("id", user.getId());
        userMap.put("type", 3);
        userMap.put("name", user.getName());

        //operator
        if(executeData.get("operator")==null){
            data.put("operator",null);
            data.put("operatorStr",null);
        }else{
            SelectionValue operator = ((ArrayList<SelectionValue>) executeData.get("operator")).get(0);
            Map<String, Object> operatorMap = new HashMap<>();
            operatorMap.put("id", operator.getId());
            operatorMap.put("type", 3);
            operatorMap.put("name", operator.getName());
            data.put("operator",Arrays.asList(operatorMap));
            data.put("operatorStr",operator.getName());
        }
        data.put("projectName",((HashMap<String, Object>) executeData.get("projectName")).get("id"));
        data.put("activityName",executeData.get("activityName"));
        data.put("copyDemand",id);

        data.put("jobNature",jobNature);
        data.put("demandCreatedTime",executeData.get("demandCreatedTime"));
        data.put("activityStartTime",executeData.get("activityStartTime"));
        data.put("activityEndTime",executeData.get("activityEndTime"));
        data.put("frontOperator",Arrays.asList(userMap));

        SelectionValue subjectPersonValue = ((ArrayList<SelectionValue>) executeData.get("subjectPerson")).get(0);
        Map<String,Object> subjectPersonMap = new HashMap<>();
        subjectPersonMap.put("id",subjectPersonValue.getId());
        subjectPersonMap.put("type",3);
        subjectPersonMap.put("name",subjectPersonValue.getName());
        List<Map<String, Object>> subjectPerson = Arrays.asList(subjectPersonMap);
        data.put("subjectPerson",subjectPerson);

        data.put("projectNameStr",executeData.get("projectNameStr"));

        data.put("industry",industry);
        data.put("depart",Arrays.asList(departMap));
        data.put("postJD",postJD);
        data.put("persons", executeData.get("persons"));
        dubboConfigService.getBizObjectFacade().saveBizObject(userId, bizObjectModel, true);

        if(executeDetails != null && executeDetails.size() > 0) {
            taskReportFacade.updateExecuteMgrInfo(id,(Date)executeData.get("activityStartTime"), (Date) executeData.get("activityEndTime"));
        }
    }

    @Override
    public void createReport(String executeDemandId,Map<String, Object> executeData,String schemaCode, Map<String,String> reportCreateTimeMap) {
        List<Map<String, Object>> executeDetails = null;
        SelectionValue subjectPersonValue = ((ArrayList<SelectionValue>) executeData.get("subjectPerson")).get(0);
        Map<String,Object> subjectPersonMap = new HashMap<>();
        subjectPersonMap.put("id",subjectPersonValue.getId());
        subjectPersonMap.put("type",3);
        subjectPersonMap.put("name",subjectPersonValue.getName());
        List<Map<String, Object>> subjectPerson = Arrays.asList(subjectPersonMap);


        if("ZXXQTB".equals(schemaCode)) {
            executeDetails  = (ArrayList<Map<String, Object>>) executeData.get("executeDetails");
        }else if("ZXXQBG".equals(schemaCode)){
            executeDetails  = (ArrayList<Map<String, Object>>) executeData.get("executeDetailList");
        }
        if(executeDetails != null && executeDetails.size() > 0) {
            SelectionValue user = ((ArrayList<SelectionValue>) executeData.get("creater")).get(0);
            SelectionValue depart = ((ArrayList<SelectionValue>) executeData.get("createdDeptId")).get(0); // String deptName = ((ArrayList<SelectionValue>) demandData.get("createdDeptId")).get(0).getName();
            //depart
            Map<String,Object> departMap = new HashMap<>();
            departMap.put("id",depart.getId());
            departMap.put("type",1);
            departMap.put("name",depart.getName());

            //frontOperator
            Map<String,Object> userMap = new HashMap<>();
            userMap.put("id",user.getId());
            userMap.put("type",3);
            userMap.put("name",user.getName());
            Map<String,Object> operatorMap = new HashMap<>();
            //operator
            if(executeData.get("operator") != null){
                SelectionValue operator = ((ArrayList<SelectionValue>) executeData.get("operator")).get(0);
                operatorMap.put("id",operator.getId());
                operatorMap.put("type",3);
                operatorMap.put("name",operator.getName());
            }
            //activityName
            String activityName = (String)executeData.get("activityName");
            //projectName
            String projectName  = (String) ((HashMap<String,Object>)executeData.get("projectName")).get("id");
            String projectNameStr = (String)executeData.get("projectNameStr");
            //demandCreatedTime
            Date demandCreatedTime = (Date) executeData.get("demandCreatedTime");
            Date activityStartTime = (Date) executeData.get("activityStartTime");
            Date activityEndTime = (Date) executeData.get("activityEndTime");
            String postJD  =  (String) executeData.get("postJD");
            String jobNature  =  (String) executeData.get("jobNature");
            String industry = "其他".equals(executeData.get("industry").toString()) ? executeData.get("qthysm").toString() : executeData.get("industry").toString();


            if("ZXXQTB".equals(schemaCode)) {
                executeDetails.forEach(
                        item->{
                            String key = item.get("year").toString() + item.get("month").toString() + item.get("cycle").toString();
                            String createTime = reportCreateTimeMap.get(key);
                            if(StringUtils.isNotBlank(createTime)) {
                                //新增执行周报信息
                                BizObjectModel bizObjectModel = new BizObjectModel();
                                bizObjectModel.setSchemaCode("ZXZBMX");
                                bizObjectModel.setFormCode("ZXZBMX");
                                bizObjectModel.setSequenceStatus("COMPLETED");
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                Map<String, Object> data = bizObjectModel.getData();


                                Date reportCreateTime = null;
                                try {
                                    reportCreateTime = sdf.parse(createTime + " 23:59:59");
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }
                                data.put("subjectPerson",subjectPerson);

                                data.put("jobNature",jobNature);
                                data.put("postJD", postJD);
                                data.put("activityStartTime", activityStartTime);
                                data.put("activityEndTime", activityEndTime);
                                data.put("reportCreateTime", reportCreateTime);
                                data.put("depart", Arrays.asList(departMap));
                                data.put("frontOperator", Arrays.asList(userMap));
                                if(MapUtils.isNotEmpty(operatorMap)){
                                    data.put("operator", Arrays.asList(operatorMap));
                                }
                                data.put("demandCreatedTime", demandCreatedTime);
                                data.put("projectName", projectName);
                                data.put("activityName", activityName);
                                data.put("executeDemandId", executeDemandId);
                                data.put("executeId", item.get("id"));
                                data.put("industry",industry);
                                data.put("dateRange",item.get("dateRange"));
                                data.put("projectNameStr",projectNameStr);
                                //planRoundNum,planGearsNum,storeNum,city,province,area,year,month,cycle,
                                data.put("year", item.get("year"));
                                data.put("month", item.get("month"));
                                data.put("cycle", item.get("cycle"));
                                data.put("province", item.get("province"));
                                data.put("city", item.get("city"));
                                data.put("area", item.get("area"));
                                data.put("planRoundNum", item.get("planRoundNum"));
                                data.put("planGearsNum", item.get("planGearsNum"));
                                data.put("storeNum", item.get("storeNum"));
                                data.put("persons", executeData.get("persons"));
                                data.put("state", "未提交");
                                data.put("isModifiable", "是");
                                data.put("isPigeonholed", "未归档");
                                dubboConfigService.getBizObjectFacade().saveBizObject(user.getId(), bizObjectModel, false);
                            }
                        }
                );
            }else if("ZXXQBG".equals(schemaCode)){
                //executeDetails = executeDetails.stream().filter(item->item.get("executeId")==null||StringUtils.isBlank(item.get("executeId").toString())).collect(Collectors.toList());
                executeDetails.forEach(
                        item->{
                            String key = item.get("year").toString() + item.get("month").toString() + item.get("cycle").toString();
                            Object needCreateReport = item.get("needCreateReport");
                            String createTime = reportCreateTimeMap.get(key);
                            if(StringUtils.isNotBlank(createTime) && needCreateReport != null) {
                                String uuid = UUID.randomUUID().toString().replace("-", "");
                                //新增执行周报信息
                                BizObjectModel bizObjectModel = new BizObjectModel();
                                bizObjectModel.setSchemaCode("ZXZBMX");
                                bizObjectModel.setFormCode("ZXZBMX");
                                bizObjectModel.setSequenceStatus("COMPLETED");
                                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                                Map<String, Object> data = bizObjectModel.getData();

                                Date reportCreateTime = null;
                                try {
                                    reportCreateTime = sdf.parse(createTime + " 23:59:59");
                                } catch (ParseException e) {
                                    e.printStackTrace();
                                }

                                data.put("postJD",postJD);
                                data.put("activityStartTime", activityStartTime);
                                data.put("activityEndTime", activityEndTime);
                                data.put("reportCreateTime", reportCreateTime);
                                data.put("depart", Arrays.asList(departMap));
                                data.put("frontOperator", Arrays.asList(userMap));
                                if(MapUtils.isNotEmpty(operatorMap)){
                                    data.put("operator", Arrays.asList(operatorMap));
                                }
                                data.put("demandCreatedTime", demandCreatedTime);
                                data.put("projectName", projectName);
                                data.put("activityName", activityName);
                                data.put("executeDemandId", executeDemandId);
                                data.put("executeId", item.get("executeId"));
                                data.put("industry",industry);
                                data.put("dateRange",item.get("dateRange"));
                                data.put("projectNameStr",projectNameStr);

                                data.put("year", item.get("year"));
                                data.put("month", item.get("month"));
                                data.put("cycle", item.get("cycle"));
                                data.put("province", item.get("province"));
                                data.put("city", item.get("city"));
                                data.put("area", item.get("area"));
                                data.put("planRoundNum", item.get("newPlanRoundNum"));
                                data.put("planGearsNum", item.get("newPlanGearsNum"));
                                data.put("storeNum", item.get("newStoreNum"));
                                data.put("persons", executeData.get("persons"));
                                data.put("state", "未提交");
                                data.put("isModifiable", "是");
                                data.put("isPigeonholed", "未归档");
                                dubboConfigService.getBizObjectFacade().saveBizObject(user.getId(), bizObjectModel, false);

                            }

                        }
                );
            }

        }
    }

    @Override
    public void updateMember(String id, String projectId, String role, String phone, String way) {
        //获取
        List<Map<String, Object>> persons = new ArrayList<>();
        //根据项目id获取组建团队中的项目专员
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl page = new PageableImpl(0, 9999);
        queryModel.setSchemaCode("XMQD");
        queryModel.setQueryCode("XMQD");
        queryModel.setPageable(page);
        FilterExpression filterExpression = Q.it("id", FilterExpression.Op.Eq, projectId);
        queryModel.setFilterExpr(filterExpression);
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("id",  "creater"));
        queryModel.setOptions(option);
        Page<BizObjectModel> bizObjectModelData = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);
        Map<String, Object> data = bizObjectModelData.getContent().get(0).getData();

        UserModel userModel = dubboConfigService.getOrganizationFacade().getUserByMobile(phone);

        if(StringUtils.isNotBlank(role)) {
            SelectionValue user = ((ArrayList<SelectionValue>) data.get("creater")).get(0);
            String userId = user.getId();
            String projectName = projectId;
            Map<String, Object> operator = new HashMap<>();
            operator.put("id", userModel.getId());
            operator.put("type", 3);
            operator.put("name", userModel.getName());
            if("add".equals(way)){
                persons = recruitmentService.getMembers(projectId);
                persons.add(operator);
                addXMZY(role, userModel);
            } else if ("delete".equals(way)){
                //根据项目id获取组建团队中的项目专员
                BizObjectQueryModel queryProjectTeamModel = new BizObjectQueryModel();
                PageableImpl projectTeamPage = new PageableImpl(0, 9999);
                queryProjectTeamModel.setSchemaCode("ProjectTeam");
                queryProjectTeamModel.setQueryCode("ProjectTeam");
                queryProjectTeamModel.setPageable(projectTeamPage);
                FilterExpression idFilterExpression = Q.it("id", FilterExpression.Op.NotEq, id);
                FilterExpression subjectNameFilterExpression = Q.it("subjectName", FilterExpression.Op.Eq, projectName);
                FilterExpression teamfilterExpression = Q.and(Arrays.asList(idFilterExpression,subjectNameFilterExpression));
                queryProjectTeamModel.setFilterExpr(teamfilterExpression);
                BizObjectQueryModel.Options projectTeamOption = new BizObjectQueryModel.Options();
                projectTeamOption.setQueryDisplayType(QueryDisplayType.APPEND);
                projectTeamOption.setCustomDisplayColumns(Arrays.asList("id", "creater","member","subjectNames"));
                queryProjectTeamModel.setOptions(projectTeamOption);
                Page<BizObjectModel> projectTeamData = dubboConfigService.getBizObjectFacade().queryBizObjects(queryProjectTeamModel);
                List<? extends BizObjectModel> content = projectTeamData.getContent();
                String subjectNames = "";
                for(int i=0 ;i<content.size(); i++) {
                    Map<String, Object> map = content.get(i).getData();
                    if (map.get("role") != null  && map.get("member") != null) {
                        SelectionValue operatorTemp = ((ArrayList<SelectionValue>) map.get("member")).get(0);
                        Map<String, Object> member = new HashMap<>();
                        member.put("id", operatorTemp.getId());
                        member.put("type", 3);
                        member.put("name", operatorTemp.getName());
                        persons.add(member);
                    }
                    subjectNames = MapUtils.getString(map, "subjectNames");
                }
                if("delete".equals(way)){
                    delXMZY(role, userModel);
                }
                fescoadQueryService.sendTextMessage(userModel.getId(),"",userModel.getName().concat("从").concat(subjectNames).concat("项目组中移除"),"项目组变动");
            }

            //更新招聘需求提报，招聘需求变更，招聘需求关闭，线上招聘周报查看，线下招聘周报查看，线上招聘周报复核，线下招聘周报复核
            updateMembersInDemand(userId, "recruitmentDemand", projectName, persons);
            updateMembersInDemand(userId, "recruitmentDemandUpdate", projectName, persons);
            updateMembersInDemand(userId, "ZPXQGB", projectName, persons);
            updateMembersInDemand(userId, "XSZPZBTJ", projectName, persons);
            updateMembersInDemand(userId, "XXZPZBTJ", projectName, persons);
            updateMembersInDemand(userId, "ZPXQZBGL", projectName, persons);
            updateMembersInDemand(userId, "XXZPXQZBGL", projectName, persons);
            //执行需求提报，执行需求变更，执行需求关闭，执行周报查看，执行周报复核
            updateMembersInDemand(userId, "ZXXQTB", projectName, persons);
            updateMembersInDemand(userId, "ZXXQBG", projectName, persons);
            updateMembersInDemand(userId, "ZXXQGB", projectName, persons);
            updateMembersInDemand(userId, "ZXZBMX", projectName, persons);
            updateMembersInDemand(userId, "ZXZBGL", projectName, persons);
            //店检测需求提报，店检需求变更，店检需求关闭，店检需求结案
            //DJXQ,DJXQBG,DJXQGB,DJXQJA
            updateMembersInDemand(userId, "DJXQ", projectName, persons);
            updateMembersInDemand(userId, "DJXQBG", projectName, persons);
            updateMembersInDemand(userId, "DJXQGB", projectName, persons);
            updateMembersInDemand(userId, "DJXQJA", projectName, persons);
            //项目立项，项目关闭，补交合同，项目延期申请
            updateMembersInDemand(userId, "XMQD", projectName, persons);
            updateMembersInDemand(userId, "projectclose", projectName, persons);
            updateMembersInDemand(userId, "bjht", projectName, persons);
            updateMembersInDemand(userId, "xmyqsq", projectName, persons);

        }
    }

    private void delXMZY(String role, UserModel userModel) {
        //根据项目id获取组建团队中的项目专员
        BizObjectQueryModel queryProjectTeam1Model = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryProjectTeam1Model.setSchemaCode("ProjectTeam");
        queryProjectTeam1Model.setQueryCode("ProjectTeam");
        queryProjectTeam1Model.setPageable(pageable);
        FilterExpression roleFilterExpression = Q.it("role", FilterExpression.Op.Eq, role);
        FilterExpression memberFilterExpression = Q.it("member", FilterExpression.Op.Like, userModel.getId());
        FilterExpression team1filterExpression = Q.and(Arrays.asList(roleFilterExpression,memberFilterExpression));
        queryProjectTeam1Model.setFilterExpr(team1filterExpression);
        BizObjectQueryModel.Options options = new BizObjectQueryModel.Options();
        options.setQueryDisplayType(QueryDisplayType.APPEND);
        options.setCustomDisplayColumns(Arrays.asList("id",  "creater","member"));
        queryProjectTeam1Model.setOptions(options);
        Page<BizObjectModel> bizObjectModelPage = dubboConfigService.getBizObjectFacade().queryBizObjects(queryProjectTeam1Model);
        if(bizObjectModelPage.getContent().size() > 0){
            String roleId="";
            List<String> roleIds= projectTeamMapper.getRoleId(role);
            if(roleIds.size()>0 && roleIds.get(0)!=null&&StringUtils.isNotEmpty(roleIds.get(0))){
                roleId=roleIds.get(0);
            }
            //回写组织角色
            projectTeamMapper.delOrgByRoleIdAndUserId(roleId, userModel.getId());
        }
    }

    private void addXMZY(String role, UserModel userModel) {
        //角色id
        String roleId="";
        List<String> roleIds= projectTeamMapper.getRoleId(role);
        if(roleIds.size()>0 && roleIds.get(0)!=null&&StringUtils.isNotEmpty(roleIds.get(0))){
            roleId=roleIds.get(0);
        }
        //管理范围(FA新零售)
        String ouScope="["+"\"2c928fbb7129a41e01712f0c81ec2ec1\""+"]";

        //获取创建时间
        String createdTime= DateFormatUtils.format(new Date(),"yyyy-MM-dd HH:mm:ss");
        String  creater="2c9280a26706a73a016706a93ccf002b";
        String unitType="USER";

        //回写组织角色
        projectTeamMapper.creatOrgRoleUser(UUID.randomUUID().toString().replace("-", ""),createdTime, creater,ouScope,roleId, userModel.getId(),unitType);
    }

    @Override
    public void addMember(String id, String schemaCode) {
        //获取
        List<Map<String, Object>> persons = new ArrayList<>();
        //根据项目id获取组建团队中的项目专员
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl page = new PageableImpl(0, 9999);
        queryModel.setSchemaCode(schemaCode);
        queryModel.setQueryCode(schemaCode);
        queryModel.setPageable(page);
        FilterExpression queryModelExpression = Q.it("id", FilterExpression.Op.Eq, id);
        queryModel.setFilterExpr(queryModelExpression);
        BizObjectQueryModel.Options options = new BizObjectQueryModel.Options();
        options.setQueryDisplayType(QueryDisplayType.APPEND);
        List<String> columns = null;
        if("DJXQ".equals(schemaCode) ||"DJXQBG".equals(schemaCode) ||"DJXQGB".equals(schemaCode)||"DJXQJA".equals(schemaCode)){
            columns = Arrays.asList("subjectName", "creater", "persons","project_name");
        }else if("XMQD".equals(schemaCode)){
            columns = Arrays.asList("id", "creater", "persons","subjectName");
        }else if("projectclose".equals(schemaCode)){
            columns = Arrays.asList("xiangmumc", "creater", "persons","xxmc");
        }else if("bjht".equals(schemaCode)){
            columns = Arrays.asList("xmmc", "creater", "persons","projectNameStr");
        }else if("xmyqsq".equals(schemaCode)) {
            columns = Arrays.asList("xmnane", "creater", "persons","projectNameStr");
        }

        options.setCustomDisplayColumns(columns);
        queryModel.setOptions(options);
        Page<BizObjectModel> bizObjectModelData = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);
        BizObjectModel model = bizObjectModelData.getContent().get(0);
        Map<String, Object> data = model.getData();
        String projectName = null;
        String userId = null;
        if("DJXQ".equals(schemaCode) ||"DJXQBG".equals(schemaCode) ||"DJXQGB".equals(schemaCode)||"DJXQJA".equals(schemaCode)){
            SelectionValue user = ((ArrayList<SelectionValue>) data.get("creater")).get(0);
            userId = user.getId();
            projectName = (String) ((HashMap<String, Object>) data.get("subjectName")).get("id");
        }else if("XMQD".equals(schemaCode)){
            SelectionValue user = ((ArrayList<SelectionValue>) data.get("creater")).get(0);
            userId = user.getId();
            projectName = id;
        }else if("projectclose".equals(schemaCode)){
            SelectionValue user = ((ArrayList<SelectionValue>) data.get("creater")).get(0);
            userId = user.getId();
            projectName = (String) ((HashMap<String, Object>) data.get("xiangmumc")).get("id");
        }else if("bjht".equals(schemaCode)){
            SelectionValue user = ((ArrayList<SelectionValue>) data.get("creater")).get(0);
            userId = user.getId();
            projectName = (String) ((HashMap<String, Object>) data.get("xmmc")).get("id");
        }else if("xmyqsq".equals(schemaCode)) {
            SelectionValue user = ((ArrayList<SelectionValue>) data.get("creater")).get(0);
            userId = user.getId();
            projectName = (String) ((HashMap<String, Object>) data.get("xmnane")).get("id");
        }
        persons = recruitmentService.getMembers(projectName);
        data.put("persons",persons);
        BizSchemaModel bizSchemaModel = dubboConfigService.getAppManagementFacade().getBizSchemaBySchemaCode(schemaCode);
        dubboConfigService.getBizObjectFacade().updateBizObjectModel(userId, model, bizSchemaModel);
    }

    @Override
    public void updatePM(String id) {
        //根据项目id获取组建团队中的项目专员
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryModel.setSchemaCode("XMJLBG");
        queryModel.setQueryCode("XMJLBG");
        queryModel.setPageable(pageable);
        FilterExpression filterExpression = Q.it("id", FilterExpression.Op.Eq, id);
        queryModel.setFilterExpr(filterExpression);
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("originalPM","PM","projectName","subjectName"));
        //项目与通告 subjectName
        queryModel.setOptions(option);
        Page<BizObjectModel> bizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);
        Map<String, Object> data = bizObjectModel.getContent().get(0).getData();


        String originalPMId = ((ArrayList<SelectionValue>) data.get("originalPM")).get(0).getId();
        String originalPMDeptId=  userMapper.getUserId(originalPMId).getDepartmentId();
        String PMId = ((ArrayList<SelectionValue>) data.get("PM")).get(0).getId();
        String PMDeptId =  userMapper.getUserId(PMId).getDepartmentId();


        String projectName  = (String) ((HashMap<String,Object>)data.get("projectName")).get("id");
        String subjectName =  null;
        if(data.get("subjectName") != null) {
            subjectName = (String) ((HashMap<String, Object>) data.get("subjectName")).get("id");
        }
        taskReportFacade.updatePM(originalPMId, originalPMDeptId, PMId, PMDeptId, projectName, subjectName);

    }

    @Override
    public void updateEM(String id) {
        //根据项目id获取组建团队中的项目专员
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryModel.setSchemaCode("ZXJLBG");
        queryModel.setQueryCode("ZXJLBG");
        queryModel.setPageable(pageable);
        FilterExpression filterExpression = Q.it("id", FilterExpression.Op.Eq, id);
        queryModel.setFilterExpr(filterExpression);
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("subjectPerson","executeDemand","executePM",
                "recruitmentDemand","recruitmentPM","DJDemand","DJPM"));
        //项目与通告 subjectName
        queryModel.setOptions(option);
        Page<BizObjectModel> bizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);
        Map<String, Object> data = bizObjectModel.getContent().get(0).getData();

        taskReportFacade.updateEM(data);
    }

    @Override
    public void updateSystemConfig() {
        jobManger.shutdownJobs();
    }

    @Override
    public boolean judgeAllDemandClosed(String projectName) {
        PageableImpl pageable = new PageableImpl(0, 9999);
        //获取审批中和待执行的招聘需求
        BizObjectQueryModel zpQueryModel = new BizObjectQueryModel();
        zpQueryModel.setSchemaCode("recruitmentDemand");
        zpQueryModel.setQueryCode("recruitmentDemand");
        zpQueryModel.setPageable(pageable);
        FilterExpression zpProjectNameFilter = Q.it("projectName", FilterExpression.Op.Eq, projectName);
        FilterExpression zpStateFilter = Q.it("state", FilterExpression.Op.In, Arrays.asList("执行中","审批中"));
        FilterExpression zpFilterExpression = Q.and(Arrays.asList(zpProjectNameFilter,zpStateFilter));
        zpQueryModel.setFilterExpr(zpFilterExpression);
        Page<BizObjectModel> zpBizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(zpQueryModel);
        if(zpBizObjectModel.getTotal() > 0 ){
            return  true;
        }

        //获取审批中和待执行的执行需求
        BizObjectQueryModel zxQueryModel = new BizObjectQueryModel();
        zxQueryModel.setSchemaCode("ZXXQTB");
        zxQueryModel.setQueryCode("ZXXQTB");
        zxQueryModel.setPageable(pageable);
        FilterExpression zxProjectNameFilter = Q.it("projectName", FilterExpression.Op.Eq, projectName);
        FilterExpression zxStateFilter = Q.it("state", FilterExpression.Op.In, Arrays.asList("执行中","审批中"));
        FilterExpression zxFilterExpression = Q.and(Arrays.asList(zxProjectNameFilter,zxStateFilter));
        zxQueryModel.setFilterExpr(zxFilterExpression);
        Page<BizObjectModel> zxBizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(zxQueryModel);
        if(zxBizObjectModel.getTotal() > 0 ){
            return  true;
        }


        //获取审批中和待执行的招聘需求
        BizObjectQueryModel djQueryModel = new BizObjectQueryModel();
        djQueryModel.setSchemaCode("DJXQ");
        djQueryModel.setQueryCode("DJXQ");
        djQueryModel.setPageable(pageable);
        FilterExpression djProjectNameFilter = Q.it("subjectName", FilterExpression.Op.Eq, projectName);
        FilterExpression djStateFilter = Q.it("state", FilterExpression.Op.In, Arrays.asList("进行中","审批中"));
        FilterExpression djFilterExpression = Q.and(Arrays.asList(djProjectNameFilter,djStateFilter));
        djQueryModel.setFilterExpr(djFilterExpression);
        Page<BizObjectModel> djBizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(djQueryModel);
        if(djBizObjectModel.getTotal() > 0 ){
            return  true;
        }
        return false;
    }

    @Override
    public void projectDelay(String projectId) {
        PageableImpl pageable = new PageableImpl(0, 9999);
        //更新项目id
        //根据id获取招聘需求提报的相关信息
        BizObjectQueryModel xtpzQueryModel = new BizObjectQueryModel();
        xtpzQueryModel.setSchemaCode("xtpz");
        xtpzQueryModel.setQueryCode("xtpz");
        xtpzQueryModel.setPageable(pageable);
        BizObjectQueryModel.Options xtpzOption = new BizObjectQueryModel.Options();
        xtpzOption.setQueryDisplayType(QueryDisplayType.APPEND);
        xtpzOption.setCustomDisplayColumns(Arrays.asList("xmyqtips","xmyqDay"));
        xtpzQueryModel.setOptions(xtpzOption);
        Page<BizObjectModel> xtpzBizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(xtpzQueryModel);

        //更新招聘需求提报时间
        BizObjectModel xtpzModel = xtpzBizObjectModel.getContent().get(0);
        int xmyqDay = 90;
        if(xtpzModel.get("xmyqDay") != null){
            xmyqDay=  Integer.parseInt(xtpzModel.get("xmyqDay").toString());
        }
        Calendar calendar = new GregorianCalendar();  // 定义calendar对象

        BizObjectQueryModel xmQueryModel = new BizObjectQueryModel();
        xmQueryModel.setSchemaCode("XMQD");
        xmQueryModel.setQueryCode("XMQD");
        xmQueryModel.setPageable(pageable);
        FilterExpression xmfilterExpression = Q.it("id", FilterExpression.Op.Eq, projectId);
        xmQueryModel.setFilterExpr(xmfilterExpression);
        BizObjectQueryModel.Options xmOption = new BizObjectQueryModel.Options();
        xmOption.setQueryDisplayType(QueryDisplayType.APPEND);
        xmOption.setCustomDisplayColumns(Arrays.asList("id","creater","subjectEndTime","subjectStartTime","projectNames"));
        xmQueryModel.setOptions(xmOption);
        Page<BizObjectModel> xmBizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(xmQueryModel);
        //更新招聘需求提报时间
        BizObjectModel xmModel = xmBizObjectModel.getContent().get(0);
        String projectName =  xmModel.get("projectNames").toString();
        Date subjectEndTime = (Date) xmModel.get("subjectEndTime");
        calendar.setTime(subjectEndTime); // 把当前系统时间赋值给calendar
        calendar.add(calendar.DATE, xmyqDay); // 在日期中增加天数,1天
        subjectEndTime = calendar.getTime(); // 把calendar转换回日期格式
        xmModel.put("subjectEndTime",subjectEndTime);
        SelectionValue user = ((ArrayList<SelectionValue>) xmModel.get("creater")).get(0);

        BizSchemaModel bizSchemaModel = dubboConfigService.getAppManagementFacade().getBizSchemaBySchemaCode("XMQD");
        dubboConfigService.getBizObjectFacade().updateBizObjectModel(user.getId(), xmModel, bizSchemaModel);
        //dubboConfigService.getBizObjectFacade().saveBizObject(user.getId(), xmModel, false);

        String xmyqtips = "是";
        if(xtpzModel.get("xmyqtips") != null) {
            xmyqtips = xtpzModel.get("xmyqtips").toString();
        }

        HashMap<String,Map<String,List<String>>> reusltMap = new HashMap();
        HashMap<String,List<String>> operatorMap = new HashMap();

        //招聘
        BizObjectQueryModel zpQueryModel = new BizObjectQueryModel();
        zpQueryModel.setSchemaCode("recruitmentDemand");
        zpQueryModel.setQueryCode("recruitmentDemand");
        zpQueryModel.setPageable(pageable);
        FilterExpression zpfilterExpression = Q.it("projectName", FilterExpression.Op.Eq, projectId);
        zpQueryModel.setFilterExpr(zpfilterExpression);
        BizObjectQueryModel.Options zpOption = new BizObjectQueryModel.Options();
        zpOption.setQueryDisplayType(QueryDisplayType.APPEND);
        zpOption.setCustomDisplayColumns(Arrays.asList("id","creater","recruitmentType","demandEndTime","demandReceiver","postJDStr","projectNameStr","operator"));
        zpQueryModel.setOptions(zpOption);
        Page<BizObjectModel> zpBizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(zpQueryModel);

        for(BizObjectModel bizObjectModel : zpBizObjectModel.getContent()){
            String operatorId = "";
            if(bizObjectModel.get("operator") != null){
                operatorId = ((ArrayList<SelectionValue>) bizObjectModel.get("operator")).get(0).getId();
            }
            String demandReceiverId = ((ArrayList<SelectionValue>) bizObjectModel.get("demandReceiver")).get(0).getId();
            String postJDStr = bizObjectModel.get("postJDStr").toString();
            String recruitmentType = bizObjectModel.get("recruitmentType").toString();
            String recruitWay = bizObjectModel.get("recruitWay").toString();
            String id = bizObjectModel.get("id").toString();

            if("是".equals(xmyqtips) && "不确定人数".equals(recruitmentType)){
                if(operatorMap.containsKey(operatorId)){
                    ((List)operatorMap.get(operatorId)).add(postJDStr);
                }else{
                    List postJDStrs =  new ArrayList<>();
                    postJDStrs.add(postJDStr);
                    operatorMap.put(operatorId, postJDStrs);
                }

                Date demandEndTime = (Date) bizObjectModel.get("demandEndTime");
                calendar.setTime(demandEndTime); // 把当前系统时间赋值给calendar
                calendar.add(calendar.DATE, xmyqDay); // 在日期中增加天数,1天
                demandEndTime = calendar.getTime(); // 把calendar转换回日期格式
                bizObjectModel.put("demandEndTime",demandEndTime);
                SelectionValue creater = ((ArrayList<SelectionValue>) bizObjectModel.get("creater")).get(0);

                BizSchemaModel bizSchemaModel2 = dubboConfigService.getAppManagementFacade().getBizSchemaBySchemaCode("recruitmentDemand");
                dubboConfigService.getBizObjectFacade().updateBizObjectModel(creater.getId(), bizObjectModel, bizSchemaModel2);

                //更新未归档的招聘周报的需求数和完成时间
                taskReportFacade.updateWeeklyReportInfo(id,demandEndTime,recruitWay);

                //更新招聘管理数据的总需求数和完成时间
                taskReportFacade.updateWeeklyReportMgrInfo(id,demandEndTime,recruitWay,recruitmentType);
            }

            if(reusltMap.containsKey(demandReceiverId)){
                if(((HashMap)reusltMap.get(demandReceiverId)).containsKey("zp")){
                    ((List)((HashMap) reusltMap.get(demandReceiverId)).get("zp")).add(postJDStr);
                }else{
                    List<String> postJDStrs = new ArrayList<>();
                    postJDStrs.add(postJDStr);
                    ((HashMap) reusltMap.get(demandReceiverId)).put("zp", postJDStrs);
                }
            }else{
                List<String> postJDStrs = new ArrayList<>();
                postJDStrs.add(postJDStr);
                Map<String,List<String>> map = new HashMap();
                map.put("zp",postJDStrs);
                reusltMap.put(demandReceiverId,map);
            }
        }

        //执行
        BizObjectQueryModel zxQueryModel = new BizObjectQueryModel();
        zxQueryModel.setSchemaCode("ZXXQTB");
        zxQueryModel.setQueryCode("ZXXQTB");
        zxQueryModel.setPageable(pageable);
        FilterExpression zxfilterExpression = Q.it("projectName", FilterExpression.Op.Eq, projectId);
        zxQueryModel.setFilterExpr(zxfilterExpression);
        BizObjectQueryModel.Options zxOption = new BizObjectQueryModel.Options();
        zxOption.setQueryDisplayType(QueryDisplayType.APPEND);
        zxOption.setCustomDisplayColumns(Arrays.asList("id","creater","activityEndTime","demandReceiver","activityName","operator","projectNameStr"));
        zxQueryModel.setOptions(zxOption);
        Page<BizObjectModel> zxBizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(zxQueryModel);

        for(BizObjectModel bizObjectModel : zxBizObjectModel.getContent()){
            //String operatorId = ((ArrayList<SelectionValue>) xmModel.get("operator")).get(0).getId();
            String demandReceiverId = ((ArrayList<SelectionValue>) bizObjectModel.get("demandReceiver")).get(0).getId();
            String activityName = bizObjectModel.get("activityName").toString();

            if(reusltMap.containsKey(demandReceiverId)){
                if(((HashMap)reusltMap.get(demandReceiverId)).containsKey("zx")){
                    ((List)((HashMap) reusltMap.get(demandReceiverId)).get("zx")).add(activityName);
                }else{
                    List<String> activityNames = new ArrayList<>();
                    activityNames.add(activityName);
                    ((HashMap) reusltMap.get(demandReceiverId)).put("zx", activityNames);
                }
            }else{
                List<String> activityNames = new ArrayList<>();
                activityNames.add(activityName);
                Map<String,List<String>> map = new HashMap();
                map.put("zx",activityNames);
                reusltMap.put(demandReceiverId,map);
            }
        }

        //店检
        BizObjectQueryModel djQueryModel = new BizObjectQueryModel();
        djQueryModel.setSchemaCode("DJXQ");
        djQueryModel.setQueryCode("DJXQ");
        djQueryModel.setPageable(pageable);
        FilterExpression djfilterExpression = Q.it("subjectName", FilterExpression.Op.Eq, projectId);
        djQueryModel.setFilterExpr(djfilterExpression);
        BizObjectQueryModel.Options djOption = new BizObjectQueryModel.Options();
        djOption.setQueryDisplayType(QueryDisplayType.APPEND);
        djOption.setCustomDisplayColumns(Arrays.asList("id","creater","djRound","executor","project_name"));
        djQueryModel.setOptions(djOption);
        Page<BizObjectModel> djBizObjectModel = dubboConfigService.getBizObjectFacade().queryBizObjects(djQueryModel);


        for(BizObjectModel bizObjectModel : djBizObjectModel.getContent()){
            String demandReceiverId = ((ArrayList<SelectionValue>) bizObjectModel.get("creater")).get(0).getId();
            String djRound = bizObjectModel.get("djRound").toString();

            if(reusltMap.containsKey(demandReceiverId)){
                if(((HashMap)reusltMap.get(demandReceiverId)).containsKey("dj")){
                    ((List)((HashMap) reusltMap.get(demandReceiverId)).get("dj")).add(djRound);
                }else{
                    List<String> djRounds = new ArrayList<>();
                    djRounds.add(djRound);
                    ((HashMap) reusltMap.get(demandReceiverId)).put("dj", djRounds);
                }
            }else{
                List<String> djRounds = new ArrayList<>();
                djRounds.add(djRound);
                Map<String,List<String>> map = new HashMap();
                map.put("dj",djRounds);
                reusltMap.put(demandReceiverId,map);
            }
        }

        //项目经理 消息提示
        for(String tempkey : reusltMap.keySet()) {
            String sb = "【" + projectName + "】项目已经延期，请及时确认并修改该项目下的";
            Map<String,List<String>> map =  reusltMap.get(tempkey);
            List<String> zpList = map.get("zp");

            List<String> zxList = map.get("zx");

            List<String> djList = map.get("dj");

            if(zpList != null &&  zpList.size() > 0){
                String zpStr = "招聘需求：";
                for(String zp : zpList){
                    zpStr += "【" +zp +"】，";
                }
                sb += zpStr.substring(0,zpStr.length()-1) + "；";
            }

            if(zxList != null &&  zxList.size() > 0){
                String zxStr = "执行需求：";
                for(String zp : zxList){
                    zxStr += "【" +zp +"】，";
                }
                sb += zxStr.substring(0,zxStr.length()-1) + "；";
            }

            if(djList != null &&  djList.size() > 0){
                String djStr = "点检需求：";
                for(String zp : djList){
                    djStr += "【" +zp +"】，";
                }
                sb += djStr.substring(0,djStr.length()-1) + "的需求结束时间！";
            }
            //System.out.println(userMapper.getUserId(tempkey).getName() + sb);
            fescoadQueryService.sendTextMessage(tempkey,"",sb,"项目延期");
        }


        //执行经理 消息提示
        for(String key : operatorMap.keySet()) {
            List<String> list =  operatorMap.get(key);
            if(list != null &&  list.size() > 0){
                String sb = "【" + projectName + "】项目已经延期，并且该项目下不确定人数的招聘需求：";
                //String sb = "的不确定人数的招聘需求已经延期90天，请及时跟进！";
                String str = "";
                for(String zp : list){
                    str += "【" +zp +"】，";
                }
                sb += str.substring(0,str.length()-1) + "的需求结束时间已经延期90天，请及时跟进！";
                //System.out.println(userMapper.getUserId(key).getName() + sb);
                fescoadQueryService.sendTextMessage(key,"",sb,"项目延期");
            }
        }
    }

    @Override
    public void updateStoreState(String id, String storeShortName, String rcsArea,String province,String cityName,String district,String detailArea,String area,String storeOutlet,String customDockingPerson,String customLinkType,String cityLevel,String state){
        // 根据项目id查询所有门店
        BizObjectQueryModel queryStoreModel = new BizObjectQueryModel();
        queryStoreModel.setSchemaCode("WHMDXX");
        queryStoreModel.setQueryCode("WHMDXX");
        PageableImpl pageable = new PageableImpl(0, 999999);
        queryStoreModel.setPageable(pageable);
        FilterExpression storeFilter = Q.it("id", FilterExpression.Op.Eq, id);
        queryStoreModel.setFilterExpr(storeFilter);
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("id", "storeStatus","zpDemand","customerStoreNum","djDemand","detailArea"));
        queryStoreModel.setOptions(option);
        Page<BizObjectModel> storeInfoDatas = dubboConfigService.getBizObjectFacade().queryBizObjects(queryStoreModel);
        Map<String, Object> data = storeInfoDatas.getContent().get(0).getData();
        String customerStoreNum = data.get("customerStoreNum").toString();
        List<String> zpDemandIds =  data.get("zpDemand") != null  ? Arrays.asList(((Map<String, Object>) data.get("zpDemand")).get("id").toString().split(";")) : null;
        List<String> djDemandIds =  data.get("djDemand") != null  ? Arrays.asList(((Map<String, Object>) data.get("djDemand")).get("id").toString().split(";")) : null;
        String oldDetailArea = data.get("detailArea") != null ? data.get("detailArea").toString() : null;
        if(zpDemandIds != null && "关闭".equals(state) && !state.equals(data.get("storeStatus").toString())) {
            taskReportFacade.updateDetailStoreState(zpDemandIds, customerStoreNum, "已取消");
        }
        if(CollectionUtils.isNotEmpty(zpDemandIds)){
            taskReportFacade.updateZPDetail(zpDemandIds,storeShortName,rcsArea,province,cityName,district,detailArea,area,storeOutlet,customDockingPerson,customLinkType,cityLevel,customerStoreNum);
        }
        if(CollectionUtils.isNotEmpty(djDemandIds)){
            taskReportFacade.updateDJDetail(djDemandIds,storeShortName,province,cityName,district,detailArea,area,storeOutlet,customDockingPerson,customLinkType,cityLevel,customerStoreNum);
        }
        if(oldDetailArea != null && !oldDetailArea.equals(detailArea)) {
            asyncDataService.clearFASQ(id);
        }
    }

    @Override
    public void HMCreateReport(String demandId, String schemaCode, String year, String month, String day, String cycle) {
        if("ZXXQTB".equals(schemaCode)) {
            //根据id获取招聘需求提报的相关信息
            BizObjectQueryModel queryModel = new BizObjectQueryModel();
            PageableImpl pageable = new PageableImpl(0, 9999);
            queryModel.setSchemaCode("ZXXQTB");
            queryModel.setQueryCode("ZXXQTB");
            queryModel.setPageable(pageable);
            FilterExpression filterExpression = Q.it("id", FilterExpression.Op.Eq, demandId);
            queryModel.setFilterExpr(filterExpression);
            BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
            option.setQueryDisplayType(QueryDisplayType.APPEND);
            option.setCustomDisplayColumns(Arrays.asList("id", "creater", "createdDeptId", "demandCreatedTime", "activityStartTime", "activityEndTime",
                    "operator", "postJD", "executeDetails", "projectName", "recruitmentType", "frontOperator", "operator", "activityName", "projectNameStr",
                    "industry", "qthysm", "projectNameStr", "jobNature","subjectPerson"));
            queryModel.setOptions(option);
            Page<BizObjectModel> executeDatas = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);
            //生成周报
            BizObjectModel model = executeDatas.getContent().get(0);
            Map<String, Object> executeData = model.getData();
            SelectionValue user = ((ArrayList<SelectionValue>) executeData.get("creater")).get(0);
            String userId = user.getId();

            //获取周报时间
            Map<String, Object> map = new HashMap<>();
            Date activityEndTime = (Date) executeData.get("activityEndTime");
            Date activityStartTime = (Date) executeData.get("activityStartTime");
            map.put("demandCreatedTime", activityStartTime);
            map.put("demandEndTime",activityEndTime);
            List<String> weeklyReportDays = RecruitmentServiceImpl.getWeeklyDayTime(map);
            List<String> cycles = RecruitmentServiceImpl.getCycle(weeklyReportDays);
            List<String> weeklyReportDayList = new ArrayList<>();
            List<String> cycleList = new ArrayList<>();
            String dateValue =  year + "-" + month + "-" +day;
            for(int i=0; i<weeklyReportDays.size(); i++){
                if(weeklyReportDays.get(i).equals(dateValue) && cycles.get(i).equals(cycle) ){
                    weeklyReportDayList.add(weeklyReportDays.get(i));
                    cycleList.add(cycles.get(i));
                }
            }
            Map<String,String> reportCreateTimeMap = getReportCreateTime(weeklyReportDayList, cycleList);
            createReport(demandId, executeData,"ZXXQTB", reportCreateTimeMap);

        }else if("recruitmentDemand".equals(schemaCode)){
            //根据id获取招聘需求提报的相关信息
            BizObjectQueryModel queryModel = new BizObjectQueryModel();
            PageableImpl pageable = new PageableImpl(0, 9999);
            queryModel.setSchemaCode("recruitmentDemand");
            queryModel.setQueryCode("recruitmentDemand");
            queryModel.setPageable(pageable);
            FilterExpression filterExpression = Q.it("id", FilterExpression.Op.Eq, demandId);
            queryModel.setFilterExpr(filterExpression);
            BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
            option.setQueryDisplayType(QueryDisplayType.APPEND);
            option.setCustomDisplayColumns(Arrays.asList("name","creater","createdDeptId","demandDetails","demandCreatedTime", "demandEndTime","recruitWay","postJD","postJDStr","operator","demandDetails",
                    "projectName","recruitmentType","frontOperator","operator","projectNameStr","customCode","subjectPerson"));
            queryModel.setOptions(option);
            Page<BizObjectModel> recruitmentDatas = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);


            //更新招聘需求提报时间
            BizObjectModel model = recruitmentDatas.getContent().get(0);
            Map<String, Object> demandData = model.getData();
            SelectionValue user = ((ArrayList<SelectionValue>) demandData.get("creater")).get(0);
            String userId = user.getId();

            //获取所有周报的所有日期以及周期
            List<String> weeklyReportDays = RecruitmentServiceImpl.getWeeklyDayTime(demandData);
            List<String> cycles = RecruitmentServiceImpl.getCycle(weeklyReportDays);
            List<String> weeklyReportDayList = new ArrayList<>();
            List<String> cycleList = new ArrayList<>();
            String dateValue =  year + "-" + month + "-" +day;
            for(int i=0; i<weeklyReportDays.size(); i++){
                if(weeklyReportDays.get(i).equals(dateValue) && cycles.get(i).equals(cycle) ){
                    weeklyReportDayList.add(weeklyReportDays.get(i));
                    cycleList.add(cycles.get(i));
                }
            }
            recruitmentService.createWeekReport(demandId, userId, weeklyReportDayList, cycleList, demandData, "recruitmentDemand",null);
        }
    }

    @Override
    public void HMCreateReportMgr(String demandId) {
        //根据id获取招聘需求提报的相关信息
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryModel.setSchemaCode("recruitmentDemand");
        queryModel.setQueryCode("recruitmentDemand");
        queryModel.setPageable(pageable);
        FilterExpression filterExpression = Q.it("id", FilterExpression.Op.Eq, demandId);
        queryModel.setFilterExpr(filterExpression);
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("name","creater","createdDeptId","demandDetails","demandCreatedTime", "demandEndTime","recruitWay","postJD","postJDStr","operator","demandDetails","projectName","recruitmentType","frontOperator","operator","projectNameStr","customCode","subjectPerson"));
        queryModel.setOptions(option);
        Page<BizObjectModel> recruitmentDatas = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);

        //更新招聘需求提报时间
        BizObjectModel model = recruitmentDatas.getContent().get(0);
        Map<String, Object> demandData = model.getData();
        SelectionValue user = ((ArrayList<SelectionValue>) demandData.get("creater")).get(0);
        String userId = user.getId();
        //生成周报管理数据
        recruitmentService.createReportMgrInfo(demandId, userId, demandData);
        String recruitmentType = demandData.get("recruitmentType").toString();
        String recruitWay = demandData.get("recruitWay").toString();
        if(!"不确定人数".equals(recruitmentType)) {
            taskReportFacade.updateDemandForById(demandId, recruitWay);
        }
    }


    private void updateMembersInDemand(String userId, String schemaCode, String projectName,  List<Map<String, Object>> persons) {
        //根据项目id获取组建团队中的项目专员
        String columns = "";
        if("ZPXQZBGL".equals(schemaCode) || "XXZPXQZBGL".equals(schemaCode)){
            columns = "subject";
        }else if("DJXQ".equals(schemaCode) ||"DJXQBG".equals(schemaCode) ||"DJXQGB".equals(schemaCode)||"DJXQJA".equals(schemaCode)){
            columns = "subjectName";
        } else if("XMQD".equals(schemaCode)){
            columns = "id";
        }else if("projectclose".equals(schemaCode)) {
            columns = "xiangmumc";
        }else if("bjht".equals(schemaCode)) {
            columns = "xmmc";
        }else if("xmyqsq".equals(schemaCode)) {
            columns = "xmnane";
        } else {
            columns = "projectName";
        }
        String tableName = dubboConfigService.getBizObjectFacade().getTableName(schemaCode);
        projectTeamMapper.updatePerson(tableName,columns, JSON.toJSONString(persons),projectName);
    }

    private  Map<String,String> getReportCreateTime(List<String> weeklyReportDays, List<String> cycles) {
        Map<String,String> reportCreateTimeMap =  new HashMap<>();
        for(int i=0; i<weeklyReportDays.size(); i++){
            String[] dateStr = weeklyReportDays.get(i).split("-");
            String year = dateStr[0];
            String month = dateStr[1];
            String cycle = cycles.get(i);
            reportCreateTimeMap.put(year+month+cycle,weeklyReportDays.get(i));
        }
        return reportCreateTimeMap;
    }

}
